/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
#define MIN(a,b) (a<b)?a:b
#define MAX(a,b) (a>b)?a:b

int* luckyNumbers (int** matrix, int matrixSize, int* matrixColSize, int* returnSize){
    *returnSize = 0;
    int columnsize = *matrixColSize;
    int *ans = (int *)malloc(sizeof(int) * matrixSize);
    for (int i = 0 ; i < matrixSize ; i++)
    {   
        int count = 1;
        int indexcolumn = 0;
        int MINraw = matrix[i][0];
        for (int j = 0 ; j < columnsize ; j++)
        {
            if (MINraw > matrix[i][j])
            {
                MINraw = matrix[i][j];
                indexcolumn = j;
            }
        }
        
        for (int m = 0; m < matrixSize ; m++)
        {
            if (MINraw > matrix[m][indexcolumn])
            {
                count++;
            }
        }

        if (count == matrixSize)
        {
            ans[(*returnSize)++] = MINraw;
        }

        
    }
    return ans;

}